/**
 * HTTP 请求工具统一导出
 */

import { request } from "./axios"

/**
 * 现代化的 HTTP 请求对象
 * 基于现有的 request 函数封装，提供更简洁的 API
 */
export const http = {
  /** GET 请求 */
  get: <T = any>(url: string, config?: { params?: Record<string, any> }) => {
    return request<T>({
      url,
      method: "get",
      params: config?.params
    })
  },

  /** POST 请求 */
  post: <T = any>(url: string, data?: any, config?: { params?: Record<string, any> }) => {
    return request<T>({
      url,
      method: "post",
      data,
      params: config?.params
    })
  },

  /** PUT 请求 */
  put: <T = any>(url: string, data?: any, config?: { params?: Record<string, any> }) => {
    return request<T>({
      url,
      method: "put",
      data,
      params: config?.params
    })
  },

  /** DELETE 请求 */
  delete: <T = any>(url: string, config?: { data?: any, params?: Record<string, any> }) => {
    return request<T>({
      url,
      method: "delete",
      data: config?.data,
      params: config?.params
    })
  },

  /** PATCH 请求 */
  patch: <T = any>(url: string, data?: any, config?: { params?: Record<string, any> }) => {
    return request<T>({
      url,
      method: "patch",
      data,
      params: config?.params
    })
  }
}

// 导出原有的 request 函数以保持向后兼容
export { request } from "./axios"
